<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot Editor Miscellaneous Tests</title>

		<style>
			@import "../../../../util/doh/robot/robot.css";
		</style>

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../../dojo/dojo.js"></script>

		<script type="text/javascript">
			dojo.require("dojo.window");
			dojo.require("dijit.robotx");
			dojo.require("dijit.tests.helpers");	// functions to help test

			dojo.ready(function(){
				doh.robot.initRobot('../test_Editor.html');
				var editor0;
				var height;
				var value;
				var editor1;
				var editor1OriginalBackgroundColor;

				function getPlugin(/*Editor*/ editor, /*String*/ command){
					return dojo.filter(editor._plugins, function(p){
						return p.command == command;
					})[0];
				}

				var registry;
				doh.register("setup", [
					{
						name: "wait for editors to load",
						timeout: 5000,
						runTest: waitForLoad
					},
					function setVars(){
						registry = doh.robot.window.require("dijit/registry");
					}
				]);

				doh.register("Miscellaneous_tests", [
					{
						name: "addStylesheet",
						timeout: 3000,
						setUp: function(){
							editor1 = registry.byId("editor1");
							editor1.setValue("<h1>header one</h1>");
							var editorTextNode = editor1.editNode.firstChild;
							editor1OriginalBackgroundColor = dojo.getComputedStyle(editorTextNode).backgroundColor;
						},
						runTest: function(){
							var d = new doh.Deferred();

							dojo.window.scrollIntoView(editor1.domNode);
							editor1.addStyleSheet('test_editor.css');

							setTimeout(d.getTestCallback(function(){
								var editorTextNode = editor1.editNode.firstChild;
								var backgroundColor = dojo.getComputedStyle(editorTextNode).backgroundColor;
								var borderStyle = dojo.getComputedStyle(editorTextNode).borderBottomStyle;
								var borderWidth = dojo.getComputedStyle(editorTextNode).borderBottomWidth;
								doh.is("header one", editorTextNode.innerHTML);
								doh.t(backgroundColor==="rgb(255, 0, 0)" || backgroundColor==="red" || backgroundColor==="#ff0000", "backgroundColor " + backgroundColor);
								doh.is("solid", borderStyle);
								doh.is("1px", borderWidth);
							}), 1000);

							return d;
						}
					},
					{
						name: "removeStylesheet",
						timeout: 3000,
						runTest: function(){
							var d = new doh.Deferred();
								editor1.removeStyleSheet('test_editor.css');

							setTimeout(d.getTestCallback(function(){
								var editorNodeText = editor1.editNode.firstChild;
								var backgroundColor = dojo.getComputedStyle(editorNodeText).backgroundColor;
								doh.is("header one", editorNodeText.innerHTML);
								doh.is(editor1OriginalBackgroundColor, backgroundColor, "backgroundColor");
							}), 1000);

							return d;
						}
					},
					{
						name: "auto expand",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("thud");
							height = dojo.style(editor0.domNode, "height");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							doh.robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.keyPress(dojo.keys.ENTER, 500);
							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								var newHeight = dojo.style(editor0.domNode, "height");
								doh.t(height < newHeight, "height decreased from " + height + " to " + newHeight);
							}), 1000);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					},
					{
						name: "font-size style migrated to editor body",
						runTest: function(){
							editor0 = registry.byId("fontSizedEditor");
							var bStyle = editor0.document.body.style["fontSize"];
							doh.t(bStyle != null, "bStyle set");
							doh.is("30pt", bStyle.toLowerCase());
						}
					},
					{
						name: "prefilters do process initial content",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("filteredEditor");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							doh.robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
							doh.robot.mouseClick({left:true}, 500);

							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								var val = editor0.get("value");
								doh.t(val.indexOf("DOJO") >= 0, "dojo in val " + val);
								doh.t(val.indexOf("notdojo") < 0, "notdojo not in val " + val);
							}), 500);

							return d;
						}
					},
					{
						name: "placeCursorAtStart (br tag) moves input before br, not inside",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("brEditor");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							doh.robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.sequence(d.getTestErrback(function(){
								editor0.placeCursorAtStart();
							}), 500);
							doh.robot.typeKeys("abc", 500);
							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								var content = editor0.get("value").replace(/[\s]/g, "");
								doh.t(content.indexOf("abc<br") >= 0, "looked for 'abc<br', found: " + content);
							}), 1000);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					},
					{
						name: "custom editor content (programmatic creation)",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("programmatic3");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							doh.robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								var content = editor0.get("value");
								doh.t(content.indexOf("Custom Initial Content.") >= 0);
							}), 1000);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					},
					{
						name: "custom filters passed in constructor are not lost",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("programmatic4");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							doh.robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								doh.t(editor0.contentPreFilters.length > 1);
							}), 1000);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					},
					{
						name: "replaceValue",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("programmatic4");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							dojo.style(editor0.domNode, "display", "none");
							editor0.replaceValue("New Value");
							dojo.style(editor0.domNode, "display", "none");
							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								dojo.style(editor0.domNode, "display", "");
								dojo.window.scrollIntoView(editor0.domNode);
								var newValue = editor0.get("value");
								editor0.undo();
								var curValue = editor0.get("value");
								doh.t(newValue.indexOf(value) < 0, "content changed with no trace of old content");
								doh.t(curValue != newValue, "undo undid the change");
								doh.t(curValue == value, "original value was restored");
							}), 1000);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					},
					{
						name: "page up/down",
						timeout: 6000,
						setUp: function(){
							editor0 = registry.byId("editor0");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							doh.robot.sequence(d.getTestErrback(function(){
								editor0.focus();
							}), 500);
							
							doh.robot.keyPress(dojo.keys.PAGE_UP, 500);
							doh.robot.typeKeys("abc", 500);
							doh.robot.keyPress(dojo.keys.PAGE_DOWN, 500);
							doh.robot.typeKeys("def", 500);
							
							doh.robot.sequence(d.getTestCallback(function(){
								var value = editor0.get("value");
								if(!dojo.isWebKit){	// commented out due to #14193
									doh.t(value.indexOf("abcdef") == 0, "editor value = " + value);
								}
							}), 500);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					},
					{
						name: "emptyAltTag",
						timeout: 20000,
						setUp: function(){
							editor0 = registry.byId("programmatic4");
							value = editor0.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();
							// Focus on the editor window
							dojo.window.scrollIntoView(editor0.domNode);
							editor0.set("value", "<img alt=\"''\" src=\"http://blogsearch.google.com/blogsearch/intl/en_ALL/images/blogs_logo.gif\">");
							doh.robot.sequence(d.getTestCallback(function(){
								// Now check the state!
								dojo.window.scrollIntoView(editor0.domNode);
								var newValue = editor0.get("value");
								var test = "alt=\"''\"";
								doh.t(newValue.indexOf(test) > 0, "content includes empty string alt");
							}), 1000);

							return d;
						},
						tearDown: function(){
							if(editor0){editor0.set("value", value);}
						}
					}

				/*****
				 * comment out test, it doesn't work
					{
						name: "caret pos #1",
						timeout: 20000,
						setUp: function(){
							editor1 = registry.byId("editor1");
							value = editor1.get("value");
						},
						runTest: function(){
							var d = new doh.Deferred();

							// Scroll editor into view, set content to list except for middle item isn't part of list
							dojo.window.scrollIntoView(editor1.domNode);
							editor1.set("value", "<ul><li>one</li><li>two</li></ul><p id='three'>three</p><ul><li>four</li><li>five</li></ul>");

							// Select middle item ("three")
							doh.robot.sequence(d.getTestErrback(function(){
								var node = dojo.byId("three", editor1.document);
								editor1.selection.selectElementChildren(node);
								editor1.selection.collapse(true);
							}), 500);

							// Press indent button so "three" becomes part of list
							doh.robot.mouseMoveAt(function(){
								return getPlugin(editor1, "indent").button.domNode;
							}, 500);
							doh.robot.mouseClick({left:true}, 500);

							doh.robot.sequence(d.getTestCallback(function(){
								doh.is("<ul><li>one</li><li>two</li><li>three</li><li>four</li><li>five</li></ul>",
										editor1.get("value"), "element 'three' indented to become part of list")
							}), 500);

							return d;
						},
						tearDown: function(){
							//if(editor0){editor0.set("value", value);}
						}
					}
				 */
				]);
				doh.run();
			});
		</script>
	</head>
</html>
